package me.kagami.myjvm.jvm.opcode;

import me.kagami.myjvm.jvm.Frame;
import org.objectweb.asm.tree.VarInsnNode;

import java.util.Arrays;

// see https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-6.html#jvms-6.5.iload
public class OpCode21iloadHandler implements OpCodeInterface {
    @Override
    public int getOpCode() {
        return 21;
    }

    // iload
    @Override
    public void handle(Frame frame) {
        System.out.println("BE OP:" + getOpCode() + " Stack:" + Arrays.toString(frame.getOperands()));
        frame.push(frame.getLocals()[((VarInsnNode) frame.getProgramCtr()).var]);
        System.out.println("AF OP:" + getOpCode() + " Stack:" + Arrays.toString(frame.getOperands()));
    }
}
